﻿#region

using Microsoft.Xna.Framework;

#endregion

namespace Pob.GameObjects.PowerUps.General
{
    internal abstract class PowerUpEffect : GameComponent
    {
        #region Fields

        internal readonly float EndTime;

        internal readonly PowerUp PowerUpOwner;

        #endregion

        #region Constructors and Destructors

        protected PowerUpEffect(Game game, PowerUp owner, float startTime, float lifeTime)
            : base(game)
        {
            PowerUpOwner = owner;

            EndTime = startTime + lifeTime;
        }

        protected PowerUpEffect(Game game, PowerUp owner)
            : base(game)
        {
            PowerUpOwner = owner;

            EndTime = float.MaxValue;
        }

        #endregion

        #region Public Methods and Operators

        public abstract void OnActivation();

        public abstract void OnDeactivation();

        public override void Update(GameTime gameTime)
        {
            if (gameTime.TotalGameTime.TotalSeconds > EndTime)
            {
                PowerUpOwner.DeactivateEffect();
            }

            base.Update(gameTime);
        }

        #endregion
    }
}